//
//  XMShowRemarkView.m
//  XiaoMiao
//
//  Created by Jim huang on 2018/5/5.
//  Copyright © 2018年 smallyou. All rights reserved.
//

#import "XMShowRemarkView.h"

@interface XMShowRemarkView ()

//背景view
@property(nonatomic,strong) UIControl *coverControl;
//内容view
@property (nonatomic,strong) UIView * contentView;
//确定
@property (nonatomic,strong) UIButton * sureBtn;
//数据
@property (nonatomic,strong) XMAlbumNewSubSubRemarkModel * remarkModel;
//数据
@property (nonatomic,strong) UIScrollView * listScrollView;
@end

@implementation XMShowRemarkView

//创建方法
+ (void)showRemarkViewWithRemarkModel:(XMAlbumNewSubSubRemarkModel *)remarkModel{
    
    
    XMShowRemarkView * remarkView = [[XMShowRemarkView alloc]initWithRemarkModel:remarkModel];
    
    [remarkView show];
    
}

- (instancetype)initWithRemarkModel:(XMAlbumNewSubSubRemarkModel *)remarkModel
{
    self = [super init];
    if (self) {
        self.remarkModel = remarkModel;
        [self setUI];
    }
    return self;
}

-(void)setUI{
    
    self.backgroundColor = kClearColor;
    
    
    //背景control
    [self.coverControl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.equalTo(self);
    }];
    
    //内容
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.width.equalTo(@300);
        make.height.equalTo(@(300));
    }];
}


#pragma mark 动画

- (void)show{
    //1. 获取当前应用的主窗口
    UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
    [keyWindow addSubview:self];
    
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(keyWindow);
    }];
    
    self.contentView.alpha = 0;
    self.coverControl.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0];
    MJWeakSelf
    [UIView animateWithDuration:0.3 animations:^{
        weakSelf.coverControl.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
        weakSelf.contentView.alpha = 1;
    }];
}

- (void)hide
{
    MJWeakSelf
    [UIView animateWithDuration:0.3 animations:^{
        
        weakSelf.contentView.alpha = 0;
        weakSelf.coverControl.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0];
        
    } completion:^(BOOL finished) {
        [self.coverControl removeAllSubviews];
        [self.coverControl removeFromSuperview];
        [self.contentView removeAllSubviews];
        [self.contentView removeFromSuperview];
        [self removeFromSuperview];
    }];
}

#pragma mark ----action----

-(void)sureAction{
    [self hide];

}



#pragma mark ----getting&setting----

//背景颜色control
-(UIControl *)coverControl{
    if (!_coverControl) {
        _coverControl = [[UIControl alloc]init];
        _coverControl.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
        [_coverControl addTarget:self action:@selector(hide) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_coverControl];
        
    }
    return _coverControl;
}

//内容
-(UIView *)contentView{
    if (!_contentView) {
        _contentView = [[UIView alloc]init];
        _contentView.backgroundColor = kWhiteColor;
        _contentView.layer.cornerRadius = 4.0f;
        _contentView.clipsToBounds = YES;
        
        //确认
        [self.sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(_contentView);
            make.height.equalTo(@(45));
        }];
        
        [self.listScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_contentView).offset(5);
            make.left.right.equalTo(_contentView);
            make.bottom.equalTo(self.sureBtn.mas_top).offset(-5);
        }];
    
        
        [self addSubview:_contentView];
    }
    return _contentView;
    
}

//确定按钮
-(UIButton *)sureBtn{
    if (!_sureBtn) {
        _sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_sureBtn setTitle:@"确定" forState:UIControlStateNormal];
        _sureBtn.titleLabel.font = kFont(14);
        [_sureBtn setTitleColor:kTextBlackColor forState:UIControlStateNormal];
        [_sureBtn setBackgroundColor:kBgColor];
        [_sureBtn addTarget:self action:@selector(sureAction) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_sureBtn];
    }
    return _sureBtn;
}

-(UIScrollView *)listScrollView{
    if (!_listScrollView) {
        
        _listScrollView = [[UIScrollView alloc]init];
        _listScrollView.backgroundColor = kWhiteColor;
        
        //名字
        UILabel * nameLabel = [[UILabel alloc]init];
        nameLabel.text = self.remarkModel.name;
        nameLabel.font = kFont(15);
        nameLabel.textColor = kTextBlackColor;
        nameLabel.textAlignment = NSTextAlignmentLeft;
        [_listScrollView addSubview:nameLabel];
        
        [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_listScrollView).offset(5);
            make.left.equalTo(_listScrollView).offset(15);
            make.right.equalTo(_listScrollView).offset(-15);
            make.width.equalTo(_listScrollView.mas_width).offset(-30);
        }];
        
        //性别年龄
        UILabel * sexAndAgeLabel = [[UILabel alloc]init];
        sexAndAgeLabel.text = [NSString stringWithFormat:@"%@   %@",self.remarkModel.sex,self.remarkModel.age];
        sexAndAgeLabel.font = kFont(15);
        sexAndAgeLabel.textColor = kTextBlackColor;
        sexAndAgeLabel.textAlignment = NSTextAlignmentLeft;
        [_listScrollView addSubview:sexAndAgeLabel];
        
        [sexAndAgeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(nameLabel.mas_bottom).offset(15);
            make.left.right.width.equalTo(nameLabel);
        }];
        
        //时间节点
        UILabel * timeLabel = [[UILabel alloc]init];
        timeLabel.text = self.remarkModel.cateSubName;
        timeLabel.font = kFont(15);
        timeLabel.textColor = kTextBlackColor;
        timeLabel.textAlignment = NSTextAlignmentLeft;
        [_listScrollView addSubview:timeLabel];
        
        [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(sexAndAgeLabel.mas_bottom).offset(20);
            make.left.right.width.equalTo(nameLabel);
        }];
        
        //类目
        UILabel * typeLabel = [[UILabel alloc]init];
        
        typeLabel.text = [NSString stringWithFormat:@"类别:  %@",self.remarkModel.cateName];
        typeLabel.font = kFont(15);
        typeLabel.textColor = kTextBlackColor;
        typeLabel.textAlignment = NSTextAlignmentLeft;
        typeLabel.numberOfLines = 0;
        [_listScrollView addSubview:typeLabel];
        
        [typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(timeLabel.mas_bottom).offset(15);
            make.left.right.width.equalTo(nameLabel);
        }];
        
        //部位
        UILabel * partLabel = [[UILabel alloc]init];
        partLabel.text = [NSString stringWithFormat:@"部位:  %@",self.remarkModel.position];
        partLabel.font = kFont(15);
        partLabel.textColor = kTextBlackColor;
        partLabel.textAlignment = NSTextAlignmentLeft;
        partLabel.numberOfLines = 0;
        [_listScrollView addSubview:partLabel];
        
        [partLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(typeLabel.mas_bottom).offset(15);
            make.left.right.width.equalTo(nameLabel);
        }];
        
        //项目
        UILabel * projectLabel = [[UILabel alloc]init];
        projectLabel.text = [NSString stringWithFormat:@"项目:  %@",self.remarkModel.project];
        projectLabel.font = kFont(15);
        projectLabel.textColor = kTextBlackColor;
        projectLabel.textAlignment = NSTextAlignmentLeft;
        projectLabel.numberOfLines = 0;
        [_listScrollView addSubview:projectLabel];
        
        [projectLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(partLabel.mas_bottom).offset(15);
            make.left.right.width.equalTo(nameLabel);

        }];
        
        
        //材料
        UILabel * materialLabel = [[UILabel alloc]init];
        materialLabel.text = [NSString stringWithFormat:@"材料:  %@",self.remarkModel.material];
        materialLabel.font = kFont(15);
        materialLabel.textColor = kTextBlackColor;
        materialLabel.textAlignment = NSTextAlignmentLeft;
        materialLabel.numberOfLines = 0;
        [_listScrollView addSubview:materialLabel];
        
        [materialLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(projectLabel.mas_bottom).offset(15);
            make.left.right.width.equalTo(nameLabel);
        }];
        
        //材料
        UILabel * remarklLabel = [[UILabel alloc]init];
        remarklLabel.text = [NSString stringWithFormat:@"备注: %@",self.remarkModel.extr];
        remarklLabel.font = kFont(15);
        remarklLabel.textColor = kTextBlackColor;
        remarklLabel.textAlignment = NSTextAlignmentLeft;
        remarklLabel.numberOfLines = 0;
        [_listScrollView addSubview:remarklLabel];
        
        [remarklLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(materialLabel.mas_bottom).offset(15);
            make.left.right.width.equalTo(nameLabel);
            make.bottom.equalTo(_listScrollView);
        }];
        
        [self.contentView addSubview:_listScrollView];
    }
    return _listScrollView;
}



@end
